﻿using System.Runtime.InteropServices;
using System.Windows;

namespace Gmantis.Controls.Chart
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct DataInfo
    {
        public int nser;
        public int npts;
        public int ndim;
        public double[] MaxVals;
        public double[] MinVals;
        public double[] Sums;
        public double[] SumsAbs;
        public StackedSum Stacked;
        public double MinX;
        public double MaxX;
        public double MinY;
        public double MaxY;
        public double MinZ;
        public double MaxZ;
        public double DeltaX;
        public Size SymbolSize;
        public Size SymbolMinSize;
        public Size SymbolMaxSize;
        public bool incX;
        public bool hasNaN;
        public void ClearLimits()
        {
            this.MinX = double.NaN;
            this.MaxX = double.NaN;
            this.MinY = double.NaN;
            this.MaxY = double.NaN;
            this.MinZ = double.NaN;
            this.MaxZ = double.NaN;
        }

        public void UpdateLimits(ValueCoordinate coord, double min, double max)
        {
            switch (coord)
            {
                case ValueCoordinate.X:
                    if ((max > this.MaxX) || double.IsNaN(this.MaxX))
                    {
                        this.MaxX = max;
                    }
                    if ((min >= this.MinX) && !double.IsNaN(this.MinX))
                    {
                        break;
                    }
                    this.MinX = min;
                    return;

                case ValueCoordinate.Y:
                    if ((max > this.MaxY) || double.IsNaN(this.MaxY))
                    {
                        this.MaxY = max;
                    }
                    if ((min >= this.MinY) && !double.IsNaN(this.MinY))
                    {
                        break;
                    }
                    this.MinY = min;
                    return;

                case ValueCoordinate.Z:
                    if ((max > this.MaxZ) || double.IsNaN(this.MaxZ))
                    {
                        this.MaxZ = max;
                    }
                    if ((min < this.MinZ) || double.IsNaN(this.MinZ))
                    {
                        this.MinZ = min;
                    }
                    break;

                default:
                    return;
            }
        }
    }
}
